package com.hmall.util;


import com.aliyun.oss.OSSClient;
import com.hdmall.business.common.util.DateTimeUtil;
import com.hmall.vo.*;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;

public class PdfUtil {
    protected static String endpoint = "http://oss-cn-beijing.aliyuncs.com";
    protected static String accessKeyId = "LTAIp8OhI23AvQo5";
    protected static String accessKeySecret = "EaCVFvRhYCNpVDkehMt18TPn8zgpwP";
    protected static String bucketName = "huangyonghui";
    public static OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
    public static BaseFont bfChinese = null;

    // public static String PDFPATH = "http://47.98.167.99:9090/manage/upload/testuploadimg/";
    public static void main(String[] args) {
        //orderSalesContPdfUpload("pdf/test2.pdf","打发打发",orderSalesContVo);
    }

    /**
     * 销售合同显示并上传
     *
     * @param title
     * @param orderSalesContVo
     */
    public static MallOrderSalesContVo orderShowSalesContPdfUpload(String ftpFileName, String title, MallOrderSalesContVo orderSalesContVo,
                                                                   UnitContactVo yiUnit, UnitContactVo jiaUnit) {

        Document document = new Document(PageSize.B5, 20, 0, 20, 0);

        try {
            //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(PDFPATH+ftpFileName));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf/" + ftpFileName));
            //bfChinese= BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
            //Font blueFont = new Font(bfChinese);
            bfChinese = BaseFont.createFont("/usr/share/fonts/lyx/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//            bfChinese = BaseFont.createFont("C:\\Windows\\Fonts\\SIMSUN.TTC,1",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
            Font ParaTitlefont = setfont(20);
            document.open();
            Paragraph titlePar = new Paragraph(title, ParaTitlefont);
            titlePar.setAlignment(Element.ALIGN_CENTER);
            document.add(titlePar);
            //加入空行
            Paragraph blankRow1 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow1);
            Font table1Fot = setfont(10);

            PdfPTable table1 = new PdfPTable(new float[]{70, 45});// 2列的表格以及单元格的宽度
            table1.setPaddingTop(3);// 顶部空白区高度
            table1.getDefaultCell().setBorder(0);
            // table1.setTotalWidth(360);//表格整体宽度
           /* PdfPCell cell1=new PdfPCell();
            cell1.set*/
            table1.addCell(createCell("供方：" + orderSalesContVo.getJiaDeptName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table1.addCell(createCell("合同编号：", table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table1);
            PdfPTable table2 = new PdfPTable(new float[]{70, 45});
            table2.setPaddingTop(3);// 顶部空白区高度
            table2.getDefaultCell().setBorder(0);
            table2.addCell(createCell("", table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table2.addCell(createCell("签署地点：", table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table2);
            PdfPTable table3 = new PdfPTable(new float[]{70, 45});
            table3.setPaddingTop(3);// 顶部空白区高度
            table3.getDefaultCell().setBorder(0);
            table3.addCell(createCell("需方:" + orderSalesContVo.getYiDeptName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            String contCreateTime = DateTimeUtil.dateToStr(orderSalesContVo.getCreateTime());
            table3.addCell(createCell("签订时间：", table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table3);
            //列表
            Font contClauseListFot = setfont(10);
            List contClauseList = new List(List.ORDERED);
            contClauseList.setIndentationLeft(50);
            for (ContClauseVo contClause : orderSalesContVo.getContClauseVos()) {

                contClauseList.add(new ListItem(contClause.getTitle() + ":" + contClause.getContent(), contClauseListFot));

            }

            document.add(contClauseList);
            //加入空行
            Paragraph blankRow2 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow2);
            int width4[] = {25, 18, 16, 16, 16, 19, 12};
            PdfPTable table4 = new PdfPTable(7);
            table4.setWidths(width4);
            table4.setPaddingTop(3);// 顶部空白区高度
            table4.getDefaultCell().setBorder(1);
            PdfPCell cellT41 = createCell("产品名称", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT42 = createCell("产品批号", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT43 = createCell("产品等级", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT44 = createCell("数量", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT45 = createCell("单价", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT46 = createCell("金额", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT47 = createCell("备注", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            table4.addCell(cellT41);
            table4.addCell(cellT42);
            table4.addCell(cellT43);
            table4.addCell(cellT44);
            table4.addCell(cellT45);
            table4.addCell(cellT46);
            table4.addCell(cellT47);
            OrderSelectVo order = orderSalesContVo.getOrderVo();
            java.util.List<OrderSelectItemVo> itemVos = order.getOrderSelectItemVos();
            //设置产品名字体
            Font pNameFt = setfont(8);
            BigDecimal weightTotal = new BigDecimal(0.0);
            for (OrderSelectItemVo item : itemVos) {
                weightTotal = weightTotal.add(item.getWeight());
                table4.addCell(createCell(item.getProducName().replace(",", "\t"), pNameFt, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductModel(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getGrade(), table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getWeight() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getCurrentPrice() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductTotalPrice() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell("", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            }
            document.add(table4);
            //合计
            int width5[] = {59, 16, 16, 19, 12};
            PdfPTable table5 = new PdfPTable(5);
            table5.setWidths(width5);
            table5.setPaddingTop(2);// 顶部空白区高度
            table5.getDefaultCell().setBorder(1);
            table5.addCell(createCell("合计", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell(weightTotal + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell("", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell(order.getPayment() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell("", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            document.add(table5);
            Paragraph blankRow4 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow4);
            int width6[] = {60, 55};
            PdfPTable table6 = new PdfPTable(2);
            table6.setWidths(width6);
            table6.setPaddingTop(3);// 顶部空白区高度
            table6.addCell(createCell("供方：" + jiaUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table6.addCell(createCell("需方：" + yiUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址：" + jiaUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址：" + yiUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table6);
            //加入空行
            Paragraph blankRow5 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow5);
            //加入空行
            Paragraph blankRow6 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow6);
            int width7[] = {60, 55};
            PdfPTable table7 = new PdfPTable(2);
            table7.setWidths(width6);
            table7.setPaddingTop(3);// 顶部空白区高度
            table7.addCell(createCell("电话：" + jiaUnit.getTel() + "传真：" + jiaUnit.getFax(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("电话：" + yiUnit.getTel(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行：" + jiaUnit.getBankName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行：" + yiUnit.getBankName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户：" + jiaUnit.getBankAccount(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户：" + yiUnit.getBankAccount(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table7);

        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        document.close();
        //上传PDF
     /*   String pdfKey=uploadPdfFile2OSS(in,ftpFileName);
        String pdfUrl=getPdfUrl(pdfKey);
        System.out.println(pdfUrl);*/
        orderSalesContVo.setOrderSalesContPdf(ftpFileName);
        //保存上传pdf地址
        //orderSalesContVo.setOrderSalesContPdf(PDFPATH+ftpFileName);
        return orderSalesContVo;
    }

    /**
     * 销售合同生成并上传
     *
     * @param title
     * @param orderSalesContVo
     */
    public static MallOrderSalesContVo orderCreateSalesContPdfUpload(String ftpFileName, String title, MallOrderSalesContVo orderSalesContVo,
                                                                     UnitContactVo yiUnit, UnitContactVo jiaUnit) {

        Document document = new Document(PageSize.B5, 20, 0, 20, 0);

        try {
            //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(PDFPATH+ftpFileName));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf/" + ftpFileName));
            bfChinese = BaseFont.createFont("/usr/share/fonts/lyx/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//            bfChinese = BaseFont.createFont("C:\\Windows\\Fonts\\SIMSUN.TTC,1",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
            //Font blueFont = new Font(bfChinese);
            Font ParaTitlefont = setfont(20);
            document.open();
            Paragraph titlePar = new Paragraph(title, ParaTitlefont);
            titlePar.setAlignment(Element.ALIGN_CENTER);
            document.add(titlePar);
            //加入空行
            Paragraph blankRow1 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow1);
            Font table1Fot = setfont(10);

            PdfPTable table1 = new PdfPTable(new float[]{70, 45});// 2列的表格以及单元格的宽度
            table1.setPaddingTop(3);// 顶部空白区高度
            table1.getDefaultCell().setBorder(0);
            // table1.setTotalWidth(360);//表格整体宽度
           /* PdfPCell cell1=new PdfPCell();
            cell1.set*/
            table1.addCell(createCell("供方：" + orderSalesContVo.getJiaDeptName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table1.addCell(createCell("合同编号：" + orderSalesContVo.getSaleContNo(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table1);
            PdfPTable table2 = new PdfPTable(new float[]{70, 45});
            table2.setPaddingTop(3);// 顶部空白区高度
            table2.getDefaultCell().setBorder(0);
            table2.addCell(createCell("", table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table2.addCell(createCell("签署地点：", table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table2);
            PdfPTable table3 = new PdfPTable(new float[]{70, 45});
            table3.setPaddingTop(3);// 顶部空白区高度
            table3.getDefaultCell().setBorder(0);
            table3.addCell(createCell("需方:" + orderSalesContVo.getYiDeptName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            String contCreateTime = DateTimeUtil.dateToStr(orderSalesContVo.getCreateTime());
            table3.addCell(createCell("签订时间：" + contCreateTime, table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table3);
            //列表
            Font contClauseListFot = setfont(10);
            List contClauseList = new List(List.ORDERED);
            contClauseList.setIndentationLeft(50);
            for (ContClauseVo contClause : orderSalesContVo.getContClauseVos()) {

                contClauseList.add(new ListItem(contClause.getTitle() + ":" + contClause.getContent(), contClauseListFot));

            }

            document.add(contClauseList);
            //加入空行
            Paragraph blankRow2 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow2);
            int width4[] = {25, 18, 16, 16, 16, 19, 12};
            PdfPTable table4 = new PdfPTable(7);
            table4.setWidths(width4);
            table4.setPaddingTop(3);// 顶部空白区高度
            table4.getDefaultCell().setBorder(1);
            PdfPCell cellT41 = createCell("产品名称", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT42 = createCell("产品批号", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT43 = createCell("产品等级", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT44 = createCell("数量", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT45 = createCell("单价", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT46 = createCell("金额", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cellT47 = createCell("备注", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            table4.addCell(cellT41);
            table4.addCell(cellT42);
            table4.addCell(cellT43);
            table4.addCell(cellT44);
            table4.addCell(cellT45);
            table4.addCell(cellT46);
            table4.addCell(cellT47);
            OrderSelectVo order = orderSalesContVo.getOrderVo();
            java.util.List<OrderSelectItemVo> itemVos = order.getOrderSelectItemVos();
            //设置产品名字体
            Font pNameFt = setfont(8);
            BigDecimal weightTotal = new BigDecimal(0.0);
            for (OrderSelectItemVo item : itemVos) {
                weightTotal = weightTotal.add(item.getWeight());
                table4.addCell(createCell(item.getProducName(), pNameFt, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductModel(), table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getGrade(), table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getWeight() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getCurrentPrice() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductTotalPrice() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
                table4.addCell(createCell("", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            }
            document.add(table4);
            //合计
            int width5[] = {59, 16, 16, 19, 12};
            PdfPTable table5 = new PdfPTable(5);
            table5.setWidths(width5);
            table5.setPaddingTop(2);// 顶部空白区高度
            table5.getDefaultCell().setBorder(1);
            table5.addCell(createCell("合计", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell(weightTotal + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell("", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell(order.getPayment() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table5.addCell(createCell("", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            document.add(table5);
            Paragraph blankRow4 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow4);
            int width6[] = {60, 55};
            PdfPTable table6 = new PdfPTable(2);
            table6.setWidths(width6);
            table6.setPaddingTop(3);// 顶部空白区高度
            table6.addCell(createCell("供方：" + jiaUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table6.addCell(createCell("需方：" + yiUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址：" + jiaUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址：" + yiUnit.getUnitName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table6);
            //加入空行
            Paragraph blankRow5 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow5);
            //加入空行
            Paragraph blankRow6 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow6);
            int width7[] = {60, 55};
            PdfPTable table7 = new PdfPTable(2);
            table7.setWidths(width6);
            table7.setPaddingTop(3);// 顶部空白区高度
            table7.addCell(createCell("电话：" + jiaUnit.getTel() + "传真：" + jiaUnit.getFax(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("电话：" + yiUnit.getTel() + "传真：" + yiUnit.getFax(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行：" + jiaUnit.getBankName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行：" + yiUnit.getBankName(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户：" + jiaUnit.getBankAccount(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户：" + yiUnit.getBankAccount(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table7);

        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        document.close();
        //上传PDF
     /*   String pdfKey=uploadPdfFile2OSS(in,ftpFileName);
        String pdfUrl=getPdfUrl(pdfKey);
        System.out.println(pdfUrl);*/
        orderSalesContVo.setOrderSalesContPdf(ftpFileName);
        //保存上传pdf地址
        //orderSalesContVo.setOrderSalesContPdf(PDFPATH+ftpFileName);
        return orderSalesContVo;
    }
   /* public static String uploadPdfFile2OSS(InputStream in, String fileName){
        String key=  OSSClientUtil.uploadPdfFile2OSS(in,fileName);


        //ossClient.getPdfImgUrl(fileName)
    }*/
    /**
     * 上传到pdf OSS服务器  如果同名文件会覆盖服务器上的
     *
     * @param instream 文件流
     * @param fileName 文件名称 包括后缀名
     * @return 出错返回"" ,唯一MD5数字签名
     */
    /*public static String uploadPdfFile2OSS(InputStream instream, String fileName) {
        //String originalFilename = file.getOriginalFilename();
        String substring = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
        Random random = new Random();
        fileName = random.nextInt(10000) + System.currentTimeMillis() + substring;
        String ret = "";
        try {
            //创建上传Object的Metadata
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setContentLength(instream.available());
            objectMetadata.setCacheControl("no-cache");
            objectMetadata.setHeader("Pragma", "no-cache");
            objectMetadata.setContentType(getcontentType(fileName.substring(fileName.lastIndexOf("."))));
            objectMetadata.setContentDisposition("inline;filename=" + fileName);
            //上传文件
            PutObjectResult putResult = ossClient.putObject(bucketName, "pdf/" + fileName, instream, objectMetadata);
            ret = putResult.getETag();
        } catch (IOException e) {
            System.out.println("上传失败！！！");
            return  null;
        } finally {
            try {
                if (instream != null) {
                    instream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }*/

    /**
     * 创建单元格(内容为文字)
     *
     * @param align
     * @return
     */
    public static PdfPCell newPdfPCell(int align, int row, String name, Font font) {
        PdfPCell cell = new PdfPCell();
       /* cell.setBorderColor(Color.black);
        cell.setBorderColorLeft(Color.BLACK);
        cell.setBorderColorRight(Color.BLACK);*/
        //cell.setBackgroundColor(bgColor);
        //cell.setBorder(border);
        cell.setHorizontalAlignment(align);
        cell.setRowspan(row);
        cell.addElement(new Paragraph(name, font));
        return cell;
    }

    /**
     * 创建单元格
     *
     * @param name
     * @return
     */
    public static PdfPCell createCell(String name, Font font, int plane, int vertical) {

        PdfPCell cell = new PdfPCell(new Paragraph(name, font));
       /* cell.setBorderColor(BaseColor.BLUE);//边框验证
        cell.setPaddingLeft(20);//左填充20
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);//水平居中
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);//垂直居中*/
        cell.setHorizontalAlignment(plane);//水平居中
        cell.setVerticalAlignment(vertical);//垂直居中
        return cell;
    }

    public static Font setfont(Integer size) {
        //中文字体,解决中文不能显示问题

        //蓝色字体
        Font font = new Font(bfChinese);
        //font.setColor(BaseColor.BLUE);
        font.setSize(size);
        //Font FontChinese1 = new Font(bfChinese, size, Font.BOLD);
        //font.setFamily("STSongStd-Light");

        return font;
    }

    /**
     * 创建一个跨多行的单元格
     *
     * @param rows  所占行数
     * @param align 对齐方式
     */
    public static PdfPCell newPdfPCellByRows(int rows, String name, int align, Font font) {
        PdfPTable iTable = new PdfPTable(1);
        PdfPCell iCell = new PdfPCell();
        iCell.setFixedHeight(iCell.getFixedHeight() * rows);
        iTable.addCell(iCell);
        //iCell.setBackgroundColor(bgColor);
        iCell.addElement(new Paragraph(name, font));
        iCell.setHorizontalAlignment(align);
        PdfPCell cell = new PdfPCell(iTable);
        return cell;
    }

    /**
     * 创建一个跨多列的单元格
     *
     * @param colspan 所占列数
     * @param align   对齐方式
     */
    public static PdfPCell newPdfPCellByColspan(int colspan, String name, int align, Font font) {
        PdfPTable iTable = new PdfPTable(1);
        PdfPCell iCell = new PdfPCell();
        iCell.setColspan(colspan);
        //iCell.setBackgroundColor(bgColor);
        iCell.setBorder(0);
        iCell.addElement(new Paragraph(name, font));
        iCell.setHorizontalAlignment(align);
        iTable.addCell(iCell);
        PdfPCell cell = new PdfPCell(iTable);
        return cell;
    }

    /**
     * 显示月度计划
     *
     * @param printProductVo
     */
    public static String orderShowPlanPdfUpload(PrintProductVo printProductVo) {

        Document document = new Document(PageSize.B5, 20, 0, 20, 0);

        try {
            //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(PDFPATH+ftpFileName));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf/" + printProductVo.getName() + ".pdf"));
            //bfChinese= BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
            //Font blueFont = new Font(bfChinese);
            bfChinese = BaseFont.createFont("/usr/share/fonts/lyx/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//            bfChinese = BaseFont.createFont("C:\\Windows\\Fonts\\SIMSUN.TTC,1",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
            Font ParaTitlefont = setfont(20);
            document.open();
            Paragraph titlePar = new Paragraph("义乌华鼎锦纶股份有限公司", ParaTitlefont);
            titlePar.setAlignment(Element.ALIGN_CENTER);
            document.add(titlePar);
            //加入空行


            Paragraph titlePar2 = new Paragraph(printProductVo.getName() + "计划采购表", ParaTitlefont);
            titlePar2.setAlignment(Element.ALIGN_CENTER);
            document.add(titlePar2);
//加入空行
            Paragraph blankRow2 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow2);
            Paragraph blankRow3 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow3);
            Paragraph blankRow4 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow4);

            Font table1Fot = setfont(11);
            PdfPTable table1 = new PdfPTable(new float[]{40, 340});// 2列的表格以及单元格的宽度
            table1.setPaddingTop(3);// 顶部空白区高度
            table1.getDefaultCell().setBorder(0);
            table1.addCell(createCell("日期：", table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            table1.addCell(createCell(printProductVo.getDate(), table1Fot, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE));
            document.add(table1);

            int width2[] = {40, 60, 30, 30, 35, 35, 35, 35, 35, 35, 60};
            PdfPTable table2 = new PdfPTable(11);
            table2.setWidths(width2);
            table2.setPaddingTop(1);// 顶部空白区高度
            PdfPCell cell1 = createCell("类型", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell2 = createCell("批号", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell3 = createCell("规格", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell4 = createCell("等级", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell5 = createCell("颜色", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell6 = createCell("光泽", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell7 = createCell("单合股", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell8 = createCell("界面形状", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell9 = createCell("捻度", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell10 = createCell("是否有网", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            PdfPCell cell11 = createCell("重量(公斤)", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
            table2.addCell(cell1);
            table2.addCell(cell2);
            table2.addCell(cell3);
            table2.addCell(cell4);
            table2.addCell(cell5);
            table2.addCell(cell6);
            table2.addCell(cell7);
            table2.addCell(cell8);
            table2.addCell(cell9);
            table2.addCell(cell10);
            table2.addCell(cell11);
            Font pNameFt = setfont(10);
            for (ProductPlanOrderVo product : printProductVo.getProductPlanOrderVoList()) {
                PdfPCell celType = createCell(product.getType(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celModel = createCell(product.getModel(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celFindAndPore = createCell(product.getFindAndPore(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celGrade = createCell(product.getGrade(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celColor = createCell(product.getColor(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celGloss = createCell(product.getGloss(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celGingleShare = createCell(product.getSingleShare(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celSection = createCell(product.getSection(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celTw = createCell(product.getTwisting(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celNt = createCell(product.getNetwork(), pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                PdfPCell celWt = createCell(product.getWeight() + "", pNameFt, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
                table2.addCell(celType);
                table2.addCell(celModel);
                table2.addCell(celFindAndPore);
                table2.addCell(celGrade);
                table2.addCell(celColor);
                table2.addCell(celGloss);
                table2.addCell(celGingleShare);
                table2.addCell(celSection);
                table2.addCell(celTw);
                table2.addCell(celNt);
                table2.addCell(celWt);
            }
            document.add(table2);
            PdfPTable table3 = new PdfPTable(new float[]{40, 340});// 2列的表格以及单元格的宽度
            table3.setPaddingTop(1);// 顶部空白区高度
            table3.getDefaultCell().setBorder(0);
            table3.addCell(createCell("合计：", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table3.addCell(createCell(printProductVo.getTotalWeigth() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            document.add(table3);
            PdfPTable table4 = new PdfPTable(new float[]{40, 340});// 2列的表格以及单元格的宽度
            table4.setPaddingTop(1);// 顶部空白区高度
            table4.getDefaultCell().setBorder(0);
            table4.addCell(createCell("备注：", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            table4.addCell(createCell(printProductVo.getRemark() + "", table1Fot, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE));
            document.add(table4);
            //            table1.addCell(createCell("合同编号：",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            // table1.setTotalWidth(360);//表格整体宽度
           /* PdfPCell cell1=new PdfPCell();
            cell1.set*/
//            table1.addCell(createCell("供方："+orderSalesContVo.getJiaDeptName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
//            table1.addCell(createCell("合同编号：",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
//            document.add(table1);

//            Paragraph blankRow2 = new Paragraph(18f, " ", ParaTitlefont);
//            document.add(blankRow2);
//            int width4[] = {25,18,16,16,16,19,12};
//            PdfPTable table4 = new PdfPTable(7);
//            table4.setWidths(width4);
//            table4.setPaddingTop(3);// 顶部空白区高度
//            table4.getDefaultCell().setBorder(1);
//            PdfPCell cellT42=createCell("产品批号",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
//            PdfPCell cellT43=createCell("产品等级",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
//            PdfPCell cellT44=createCell("数量",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
//            PdfPCell cellT45=createCell("单价",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
//            PdfPCell cellT46=createCell("金额",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
//            PdfPCell cellT47=createCell("备注",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
//            table4.addCell(cellT41);
//            table4.addCell(cellT42);
//            table4.addCell(cellT43);
//            table4.addCell(cellT44);
//            table4.addCell(cellT45);
//            table4.addCell(cellT46);
//            table4.addCell(cellT47);
            /*OrderSelectVo order= orderSalesContVo.getOrderVo();
            java.util.List<OrderSelectItemVo> itemVos= order.getOrderSelectItemVos();
            //设置产品名字体
            Font pNameFt=setfont(8);
            Integer weightTotal=0;
            for(OrderSelectItemVo item:itemVos){
                weightTotal+=item.getWeight();
                table4.addCell(createCell(item.getProducName().replace(",","\t"),pNameFt,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductModel(),pNameFt,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getGrade(),table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getWeight()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getCurrentPrice()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductTotalPrice()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            }
            document.add(table4);*/
            //合计
           /* int width5[] = {59,16,16,19,12};
            PdfPTable table5 = new PdfPTable(5);
            table5.setWidths(width5);
            table5.setPaddingTop(2);// 顶部空白区高度
            table5.getDefaultCell().setBorder(1);
            table5.addCell(createCell("合计",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell(weightTotal+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell(order.getPayment()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            document.add(table5);*/
            //加入空行

        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        document.close();
        //上传PDF
     /*   String pdfKey=uploadPdfFile2OSS(in,ftpFileName);
        String pdfUrl=getPdfUrl(pdfKey);
        System.out.println(pdfUrl);*/

        return "pdf/" + printProductVo.getName() + ".pdf";
    }
}


